//
//  BaseVC.m
//  CoolJF
//
//  Created by Apple on 2017/2/23.
//  Copyright © 2017年 Ubi. All rights reserved.
//

#import "BaseVC.h"



@interface BaseVC ()

@end

@implementation BaseVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //导航条
    WS(ws);
    [self.naviBarContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.centerX.equalTo(ws.view);
    }];
    [self.baseContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.bottom.centerX.equalTo(ws.view);
    }];
    
}


- (void)setIsShowCustomBar:(BOOL)isShowCustomBar
{
    _isShowCustomBar = isShowCustomBar;
    if(isShowCustomBar)
    {
        self.navigationController.navigationBar.hidden = YES;
        self.naviBarContentView.hidden = NO;
        self.baseContentView.hidden =NO;
          WS(weakSelf);
        [self.naviBarContentView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(UI_NAVI_HEIGHT);
        }];
        [self.baseContentView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.naviBarContentView.mas_bottom);
        }];
        [self setupNaviBarContentViewChildView];
    }
    else
    {
        self.navigationController.navigationBar.hidden = NO;
        self.naviBarContentView.hidden = YES;
        self.baseContentView.hidden =YES;
        [self.naviBarContentView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(CGFLOAT_MIN);
        }];
        [self.baseContentView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(CGFLOAT_MIN);
        }];
    }
}

- (void)setIsShowBottomLine:(BOOL)isShowBottomLine
{
    self.naviBarBottomLine.hidden = !isShowBottomLine;
}
- (void)setBaseNavigationBarSeperatLineShow:(BOOL)show
{
    self.isShowBottomLine = show;
    self.naviBarBottomLine.backgroundColor = [UIConstantColor getDefaultSeperaterColor];
}

- (void)setupNaviBarContentViewChildView
{
    WS(ws);
    [self.baseLeftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(UI_NAVI_BAR_HEIGHT,UI_NAVI_BAR_HEIGHT));
        make.left.equalTo(ws.naviBarContentView).offset(BUTTON_DEFAULT_MARGIN);
        make.bottom.equalTo(ws.naviBarContentView);
    }];
    [self.baseRightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(UI_NAVI_BAR_HEIGHT,UI_NAVI_BAR_HEIGHT));
        make.right.equalTo(ws.naviBarContentView).offset(-BUTTON_DEFAULT_MARGIN);
        make.bottom.equalTo(ws.naviBarContentView);
    }];
    
    [self.baseNavigationBarLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(ws.naviBarContentView);
        make.height.mas_equalTo(UI_NAVI_BAR_HEIGHT);
        make.bottom.mas_equalTo(ws.naviBarContentView);
        make.width.mas_equalTo(@200);
    }];
    
    [self.naviBarBottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(ws.naviBarContentView);
        make.height.mas_equalTo(0.5);
    }];
}

#pragma mark - handle

- (void)setBaseNavigationBarTitle:(NSString *)barTitle
{
    self.baseNavigationBarLabel.text = barTitle;
}

- (void)setBaseNavigationBarColor:(UIColor *)barColor
{
    self.baseNavigationBarLabel.textColor = barColor;
}
- (void)setBaseNavigationBarBackgroundColor:(UIColor *)barColor{
    self.naviBarContentView.backgroundColor = barColor;
}

- (void)addLeftButtonSelector:(SEL)selector
{
    [self.baseLeftButton removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
    [self.baseLeftButton addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
}

- (void)addRightButtonSelector:(SEL)selector
{
    [self.baseRightButton removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
    [self.baseRightButton addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
}

- (void)setLeftButtonImage:(UIImage *)image{
    [self.baseLeftButton setImage:image forState:UIControlStateNormal];
}
- (void)setLeftButtonLightImage:(UIImage *)image{
    [self.baseLeftButton setImage:image forState:UIControlStateHighlighted];
}
- (void)setRightButtonImage:(UIImage *)image{
    [self.baseRightButton setImage:image forState:UIControlStateNormal];
}
- (void)setRightButtonLightImage:(UIImage *)image{
    [self.baseRightButton setImage:image forState:UIControlStateHighlighted];
}
- (void)setLeftButtonTitle:(NSString *)title
{
    [self.baseLeftButton setTitle:title forState:UIControlStateNormal];
}
- (void)setRightButtonTitle:(NSString *)title
{
    [self.baseRightButton setTitle:title forState:UIControlStateNormal];
}
- (void)setRightButtonEnableTitle:(NSString *)enableTitle
{
  [self.baseRightButton setTitle:enableTitle forState:UIControlStateDisabled];
}
- (void)setRightButtonSelectedTitle:(NSString *)selecteTitle
{
    [self.baseRightButton setTitle:selecteTitle forState:UIControlStateSelected];
}

- (void)updateLeftButtonWidth:(CGFloat)width{
    [self.baseLeftButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(width);
    }];
}

- (void)updateRightButtonWidth:(CGFloat)width{
    [self.baseRightButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(width);
    }];
}



#pragma mark - 设置状态条
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return self.statusStyle;
}

- (void)setStatusStyle:(UIStatusBarStyle)statusStyle
{
    _statusStyle = statusStyle;
    [self setNeedsStatusBarAppearanceUpdate];
    
    //tabVC控制管理器下 通过导航的view来设置
    //设置状态栏颜色
    UIBarStyle barStyle = (UIBarStyle)statusStyle;
    if (self.navigationController) {
        self.navigationController.navigationBar.barStyle = barStyle;
    }
}
- (void)setBaseStatusBarBackgroundColor:(UIColor *)color
{
    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
        statusBar.backgroundColor = color;
    }
    [self setNeedsStatusBarAppearanceUpdate];
}

#pragma mark - set/get
- (UIView *)naviBarContentView
{
    if(_naviBarContentView == nil)
    {
        _naviBarContentView = [UIView new];
        _naviBarContentView.backgroundColor = [UIConstantColor getDefaultNaviBackgroundColor];
        [self.view addSubview:_naviBarContentView];
    }
    return _naviBarContentView;
}

- (UIView *)baseContentView
{
    if(_baseContentView == nil)
    {
        _baseContentView = [UIView new];
        [self.view addSubview:_baseContentView];
    }
    return _baseContentView;
}

- (UIView *)naviBarBottomLine
{
  if(_naviBarBottomLine == nil)
  {
      _naviBarBottomLine = [UIView new];
      _naviBarBottomLine.backgroundColor = [UIConstantColor getDefaultSeperaterColor];
      [self.naviBarContentView addSubview:_naviBarBottomLine];
  }
    return _naviBarBottomLine;
}

- (UIButton *)baseLeftButton
{
    if(_baseLeftButton == nil)
    {
        _baseLeftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_baseLeftButton.titleLabel setFont:[UIConstantFont getFontW6_H17]];
        [_baseLeftButton setTitleColor:[UIConstantColor getNaviRightButtonNormalColor] forState:UIControlStateNormal];
//        _baseLeftButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
//        _baseLeftButton.imageView.clipsToBounds = YES;
        [self.naviBarContentView addSubview:_baseLeftButton];
    }
    return _baseLeftButton;
}

- (UIButton *)baseRightButton
{
    if(_baseRightButton == nil)
    {
        _baseRightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_baseRightButton.titleLabel setFont:[UIConstantFont getFontW6_H17]];
        [_baseRightButton setTitleColor:[UIConstantColor getNaviRightButtonNormalColor] forState:UIControlStateNormal];
        [_baseRightButton setTitleColor:[UIConstantColor getNaviRightButtonDisEnbleColor] forState:UIControlStateDisabled];
        [self.naviBarContentView addSubview:_baseRightButton];
    }
    return _baseRightButton;
}

- (UILabel *)baseNavigationBarLabel
{
  if(_baseNavigationBarLabel == nil)
  {
      _baseNavigationBarLabel = [UILabel new];
      _baseNavigationBarLabel.textAlignment = NSTextAlignmentCenter;
      _baseNavigationBarLabel.font = [UIConstantFont getFontW9_H17];
      _baseNavigationBarLabel.textColor = [UIColor blackColor];
      [self.naviBarContentView addSubview:_baseNavigationBarLabel];
  }
    return _baseNavigationBarLabel;
}


@end
